// https://nuxt.com/docs/api/configuration/nuxt-config
import removeConsole from "vite-plugin-remove-console";
import type {NuxtPage} from "@nuxt/schema";

export default defineNuxtConfig({
  compatibilityDate: '2025-05-15',
  devtools: { enabled: true },
  vite: {
    plugins: [
      removeConsole(),
    ]
  },
  build: {
    // 打包文件分析
    analyze: true,
    transpile: ['naive-ui', "vueuc"],
  },
  css: [
    // 全局的css
    '@/assets/style/index.css',
  ],
  icon: {
    // 默认使用远程服务
    serverBundle: 'remote',
  },
  modules: [
    '@nuxt/eslint',
    '@nuxt/icon',
    '@nuxt/scripts',
    '@nuxt/ui',
    '@pinia/nuxt',
    'pinia-plugin-persistedstate',
    'nuxtjs-naive-ui',
    '@unocss/nuxt', // unocss
  ],
  vueuse: {
    ssrHandlers: true,
  },
  imports: {
    dirs: ['./stores'],
  },
  hooks: {
    'pages:extend': (pages: NuxtPage[]) => {
      const matchText = ["components", "component"]

      function removePagesMatching() {
        const pagesToRemove: Array<any> = []
        for (const page of pages) {
          if (page.file) {
            if (matchText.some((text) => page.file && page.file.toLowerCase().includes(text))) {
              pagesToRemove.push(page)
            }
          }
        }
        for (const page of pagesToRemove) {
          pages.splice(pages.indexOf(page), 1)
        }
      }

      removePagesMatching()
    }
  },
  devServer: {
    host: "0.0.0.0",
    port: 3000,
  },
} as any)